package com.xgkj.diyiketang.weidget;


import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

import com.xgkj.diyiketang.util.PalLog;

/**
 * class name MyScrollView.java
 * author renhaibin
 * date 2015-4-14 下午1:39:40
 *
 */
public class MyScrollView extends ScrollView{
	private static final String TAG = "MyScrollView";
	private OnScrollListener mListener;

	public MyScrollView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public MyScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MyScrollView(Context context) {
		super(context);
	}
	
	public void setOnScrollListener(OnScrollListener listener){
		mListener = listener;
	}
	//判断滚动到底执行onscroll;
	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		super.onScrollChanged(l, t, oldl, oldt);
//		PalLog.e(TAG, getHeight() + "");
//		PalLog.e(TAG, getScrollY()+"");
//		PalLog.e(TAG, computeVerticalScrollRange()+"所有");
		if(mListener != null && getHeight() + getScrollY() >= computeVerticalScrollRange()){
			mListener.onScroll();
		}
	}
	
	public interface OnScrollListener{
		public void onScroll();
	}

	/*protected int computeVerticalScrollRange() {
		final int count = getChildCount();
		final int contentHeight = getHeight() ;//- mPaddingBottom - mPaddingTop;
		if (count == 0) {
			return contentHeight;
		}

		int scrollRange = getChildAt(0).getBottom();
		PalLog.e(TAG,scrollRange+"底部" +getChildAt(0).getTop());
		final int scrollY = getScrollY();
		PalLog.e(TAG,scrollY+"滑动");
		final int overscrollBottom = Math.max(0, scrollRange - contentHeight);
		PalLog.e(TAG,overscrollBottom+"隐藏");
		if (scrollY < 0) {
			scrollRange -= scrollY;
		} else if (scrollY > overscrollBottom) {
			scrollRange += scrollY - overscrollBottom;
		}

		return scrollRange;
	}*/





}
